/*
 * Copyright 2008 Zoundry LLC, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */
package org.zoundry.gaedt.core.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.util.jar.JarFile;

/**
 * Contains convenience methods used to close streams and other i/o constructs.
 */
public final class ZGaeCloser
{
    /**
     * C'tor.
     */
    private ZGaeCloser()
    {
    }

    /**
     * Closes the InputStream and eats any IOException.
     *
     * @param aIn
     *            can be null
     */
    public static void close(InputStream aIn)
    {
        if (aIn != null)
        {
            try
            {
                aIn.close();
            }
            catch (IOException e)
            {
                // eat the exception
            }
        }
    }

    /**
     * Closes Reader and eats any IOException
     *
     * @param aReader
     */
    public static void close(Reader aReader)
    {
        if (aReader != null)
        {
            try
            {
                aReader.close();
            }
            catch (IOException e)
            {
                // eat the exception
            }
        }
    }

    /**
     * Closes Writer and eats any IOException
     *
     * @param aWriter
     */
    public static void close(Writer aWriter)
    {
        if (aWriter != null)
        {
            try
            {
                aWriter.close();
            }
            catch (IOException e)
            {
                // eat the exception
            }
        }
    }

    /**
     * Closes OutputStream and eats any IOException
     *
     * @param aOut
     */
    public static void close(OutputStream aOut)
    {
        if (aOut != null)
        {
            try
            {
                aOut.close();
            }
            catch (IOException e)
            {
                // eat the exception
            }
        }
    }

    /**
     * Closes JarFile and eats any IOException
     *
     * @param aJarFile
     */
    public static void close(JarFile aJarFile)
    {
        if (aJarFile != null)
        {
            try
            {
                aJarFile.close();
            }
            catch (IOException io)
            {
                // eat it
            }
        }
    }
}
